package org.jeecg.modules.front.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.annotation.UserLoginToken;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@Slf4j
@Api(tags="小程序-上传图片")
@RequestMapping("/mobile/image")
public class ImageUploadController {

//    @Value("${upload.path}")
//    private String uploadPath;

    @ApiOperation(value = "获取", notes = "获取")
    @PostMapping("/list")
    @UserLoginToken
    public String uploadImag2e() {
        return "测试";
    }


    @ApiOperation(value = "上传图片", notes = "上传图片")
    @PostMapping("/upload")
    public String uploadImage(@RequestParam("file") MultipartFile file) {
        System.out.println("222222");
        try {
            // 获取文件名
            String fileName = file.getOriginalFilename();
            // 指定保存路径
            String filePath = "resources/images" + "/" + fileName;
            // 保存文件到本地
            file.transferTo(new File(filePath));
            return "上传成功";
        } catch (IOException e) {
            e.printStackTrace();
            return "上传失败";
        }
    }
}
